package top.soulblack.purchasesale.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.soulblack.purchasesale.mapper.GoodsColorMapper;
import top.soulblack.purchasesale.model.GoodsColor;

import java.util.List;

/**
 * @Author: 廉雪峰
 * @Date: 2019/5/11 20:49
 * @Version 1.0
 */
@Service
public class GoodsColorService {

    @Autowired
    private GoodsColorMapper goodsColorMapper;

    public List<GoodsColor> selectAll() {
        return goodsColorMapper.selectAll();
    }

    public List<String> selectGroups() {
        return goodsColorMapper.selectGroups();
    }

    public void addColor(GoodsColor goodsColor) {
        goodsColorMapper.addColor(goodsColor);
        return;
    }

    public boolean existColor(String name) {
        int num  = goodsColorMapper.existColor(name);
        if (num == 1) {
            return true;
        }
        return false;
    }

    public boolean deleteColor(Integer colorId) {
        List<Integer> num = goodsColorMapper.deleteById(colorId);
        if (num != null) {
            return true;
        }
        return false;
    }

    public boolean updateColor(GoodsColor goodsColor) {
        int num = goodsColorMapper.updateByPrimaryKey(goodsColor);
        if (num == 1) {
            return true;
        }
        return false;
    }

    public List<GoodsColor> selectForName(String colorName) {
        return goodsColorMapper.selectForName(colorName);
    }

    public List<GoodsColor> selectForGroup(String group) {
        return goodsColorMapper.selectForGroup(group);
    }

    public boolean updateGroup(String newGroup, String oldGroup) {
        int num = goodsColorMapper.updateGroup(newGroup, oldGroup);
        if (num >= 1) {
            return true;
        }
        return false;
    }

    public boolean deleteGroup(String oldGroup) {
        int num = goodsColorMapper.deleteGroup(oldGroup);
        if (num >= 1) {
            return true;
        }
        return false;
    }
    public boolean selectColor(Integer colorId){
        List<Integer> num = goodsColorMapper.selectColor(colorId);
        if (num  != null) {
            return true;
        }
        return false;
    }
}
